﻿using NHibernate;
using NHibernate.Criterion;
using System.Collections.Generic;
using MSP.Data.Domain;
using MSP.Data.NHibernate;

namespace MSP.Data.Repositories
{
    public class ProductActionRepository : Repository<ProductAction>
    {
        public ProductActionRepository(ISession session)
            : base(session)
        {
        }

        public void SaveProductAction(ProductAction productAction)
        {
            Add(productAction);
        }

        public void UpdateProductAction(ProductAction productAction)
        {
            Update(productAction);
        }

        public void DeleteProductAction(int Id)
        {
            ProductAction customer = GetProductActionById(Id);
            if (customer != null)
                Delete(customer);
        }

        public ProductAction GetProductActionById(int Id)
        {
            return Session.CreateCriteria<ProductAction>()
                          .Add(Restrictions.Eq("Id", Id))
                          .UniqueResult<ProductAction>();
        }

        public IList<ProductAction> GetAllProductAction()
        {
            return (Session.CreateCriteria<ProductAction>()
               .List<ProductAction>() as List<ProductAction>);
        }

    }
}
